package com.hyf.serviceedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyf.serviceedu.entity.EduTeacher;
import com.hyf.serviceedu.mapper.EduTeacherMapper;
import com.hyf.serviceedu.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2021-04-17
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {
	
	// 前端查询讲师列表分页
	@Override
	public Map<String, Object> getTeacherFromtList(Page<EduTeacher> pageParam) {
		QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
		queryWrapper.orderByDesc("id");
		// 把分页数据封装到pageTeacher对象中
		baseMapper.selectPage(pageParam, queryWrapper);
		List<EduTeacher> records = pageParam.getRecords();
		long current = pageParam.getCurrent();
		long pages = pageParam.getPages();
		long size = pageParam.getSize();
		long total = pageParam.getTotal();
		
		boolean hasNext = pageParam.hasNext();// 当前是否有下一页
		boolean hasPrevious = pageParam.hasPrevious();// 当前是否有上一页
		// 把这些数据封装到map集合中
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("items", records);
		map.put("current", current);
		map.put("pages", pages);
		map.put("size", size);
		map.put("total", total);
		map.put("hasNext", hasNext);
		map.put("hasPrevious", hasPrevious);
		return map;
	}
}
